package com.gwtjs.icustom.controller.manager;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.gwtjs.icustom.entity.ResultWrapper;
import com.gwtjs.icustom.mapper.AmbariInstallInfoMapper;
import com.gwtjs.icustom.pojo.AmbariInstallInfo;

@RestController @RequestMapping("/ambari_ins")
public class ManageAmbariInstallInfoController {

	@Autowired
	private AmbariInstallInfoMapper infoMapper;
	private final static Logger logger = LoggerFactory.getLogger(ManagerUserController.class);

	@GetMapping("/get/list")
	public ResultWrapper queryList() {
		List<AmbariInstallInfo> list = infoMapper.queryAmbariInstallInfoList();
		return ResultWrapper.constructSuccessResult(list);

	}

	@GetMapping("/get/{id}/{ambariIp}")
	public ResultWrapper queryId(@PathVariable("id") Integer id,@PathVariable("ambariIp") String ambariIp) {
		logger.info("Ambari Install Info get ID:{},IP:{}",id,ambariIp);
		AmbariInstallInfo in=new AmbariInstallInfo();
		in.setAmbariIp(ambariIp);
		in.setId(id);
		AmbariInstallInfo info = infoMapper.queryInstallInfo(in);
		return ResultWrapper.constructSuccessResult(info);

	}

	@GetMapping("/get/max_id")
	public ResultWrapper queryMaxId() {
		Integer maxId = infoMapper.queryInfoMaxId();
		return ResultWrapper.constructSuccessResult(maxId);
	}

	@GetMapping("/count")
	public ResultWrapper queryByIpCount(@RequestBody AmbariInstallInfo info) {
		Integer result = infoMapper.queryByIpCount(info);
		logger.info("Ambari Install Info data item count:{}",result);
		return ResultWrapper.constructSuccessResult(result);
	}

	@DeleteMapping("/del")
	public ResultWrapper deleteInstallInfo(@RequestBody AmbariInstallInfo info) {
		Integer result = infoMapper.deleteInstallInfo(info);
		return ResultWrapper.constructSuccessResult(result);

	}

	@DeleteMapping("/batch_del")
	public ResultWrapper batchDeleteInstallInfo(@RequestBody List<AmbariInstallInfo> records) {
		Integer result = infoMapper.batchDeleteInstallInfo(records);
		return ResultWrapper.constructSuccessResult(result);
	}

	@PostMapping("/add")
	public ResultWrapper add(@RequestBody AmbariInstallInfo info) {
		/*Integer result = */infoMapper.addInstallInfo(info);
		return ResultWrapper.constructSuccessResult(info);

	}

}
